export interface MapCenterConfig {
  lon: number;
  lat: number;
  height?: number;
}

export interface MapConfig {
  /** 天地图 Token */
  tdtToken: string;
  /** 默认中心点，经纬度与高度（米） */
  center: MapCenterConfig;
}

// 允许通过环境变量覆盖配置，但默认使用下方值
const toNumber = (v: string | undefined, def: number) => {
  if (v == null || v === '') return def;
  const n = Number(v);
  return Number.isFinite(n) ? n : def;
};

export const MAP_CONFIG: MapConfig = {
  // 可改为环境变量 VITE_TDT_TOKEN 覆盖
  tdtToken: (import.meta as any).env?.VITE_TDT_TOKEN,
  center: {
    lon: toNumber((import.meta as any).env?.VITE_MAP_CENTER_LON, 116.397428),
    lat: toNumber((import.meta as any).env?.VITE_MAP_CENTER_LAT, 39.90923),
    height: toNumber((import.meta as any).env?.VITE_MAP_CENTER_HEIGHT, 15000)
  }
};

export default MAP_CONFIG;

